package com.dhcc.dubbo.controller;

import java.util.Random;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dhcc.dubbo.bean.response.Result;
import com.dhcc.dubbo.bean.response.ResultCode;
import com.dhcc.dubbo.service.UserService;

@RestController
@RequestMapping("/user")
public class UserController {
    @Reference(version = "1.0.0")
    UserService userService;

    @RequestMapping("/getAllUsers/{i}")
    public Result getAllUsers(@PathVariable(name = "i") int i) {
    	if(StringUtils.isEmpty(i)) {
    		i = new Random().nextInt(10);
    	}
        return new Result(ResultCode.SUCCESS,userService.getAllUsers(i));
    }
    @RequestMapping("/getUserByUserName")
    public Result getUserByUserName(String username) {
        return new Result(ResultCode.SUCCESS,userService.getUserByUserName(username));
    }
    @RequestMapping("/getUserByName/{name}")
    public Result getUserByName(@PathVariable(name = "name") String name) {
    	return new Result(ResultCode.SUCCESS,userService.getUserByName(name));
    }
}